package main.com.hjy.jdbc.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtils {

    //定义驱动常量
    private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
    //定义连接数据库的URL常量格式:jdbc:数据库系统名://数据库IP地址:数据库端口号/要操作的数据库名
    private static final String URL = "jdbc:mysql://192.168.56.101:3306/hjy";
    //定义连接数据库的用户名常量
    private static final String USER = "root";
    //定义连接数据库的密码常量
    private static final String PASS = "150316";

    public static Connection getConnection()
    {
        Connection conn = null;
        try {
            //加载驱动
            Class.forName(DRIVER);
            //通过DriverManager创建数据库的连接对象
            conn  = DriverManager.getConnection(URL, USER, PASS);
            return conn;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
}
